package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * 优惠活动分录
 *
 * @author: 袁首京<yuanshoujing@gmail.com> 16/4/13
 */
@Entity
@Table(name = "goods_package_entry")
public class GoodsPackageEntry extends AbstractVersionEntity {

	@JSONField(serialize = false)
	@ManyToOne
	protected GoodsPackage owner;

	@ManyToOne
	protected Goods goods; // 商品

	@Transient
	private String goodsPicturesName; //商品图片

    public String getGoodsPicturesName() {

        if (this.goodsPicturesName != null){
            return this.goodsPicturesName;
        }
        if (this.goods != null){
            return this.goods.getPictureName();
        }

        return goodsPicturesName;
    }

    public void setGoodsPicturesName(String goodsPicturesName) {
        this.goodsPicturesName = goodsPicturesName;
    }

    @Column(nullable = false)
	protected BigDecimal quantity = BigDecimal.ZERO; // 数量

	@Column(nullable = false)
	protected BigDecimal price = BigDecimal.ZERO;// 单价

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public GoodsPackage getOwner() {
		return owner;
	}

	public void setOwner(GoodsPackage owner) {
		this.owner = owner;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public BigDecimal getQuantity() {
		return quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

}
